#include <cstdio>
#include <vector>


/**
 * 无向图的邻接表
 * 
 * */
 
int main() {
    std::vector<std::vector<int>> graph(6, std::vector<int>());

    int edges[5][2] = {
        // 1-2
        {1, 2},
        // 2-3
        {2, 3},
        // 3-5
        {3, 5},
        // 4-5
        {4, 5},
        // 5-1
        {5, 1}
    };

    for (int i = 0; i < 5; i++) {
        graph[edges[i][0]].push_back(edges[i][1]);
        graph[edges[i][1]].push_back(edges[i][0]);
    }

    printf("有向图的邻接表遍历:\n");

    for (int i = 0; i < graph.size(); i++) {
        printf("%d -> ", i);
        for (int j = 0; j < graph[i].size(); j++) {
            printf("%d ", graph[i][j]);
        }
        printf("\n");
    }

	return 0;

}
